
package com.quanyan.runningriding.web.running.Admin;


import com.quanyan.api.APIResponse;
import com.quanyan.common.Plugin.PageObj;
import com.quanyan.common.validation.base.Insert;
import com.quanyan.runningriding.entity.vo.run.MusicTypeVo;
import com.quanyan.runningriding.service.RunMusicService;
import org.apache.commons.collections.MapUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;


/**
 * RunMusicController
 *
 * @author Tu Chun
 * @date 2016/8/23
 */
@RestController
@RequestMapping(value = "/admin/api/run")
public class MusicTypeAdminController {
    @Autowired
    private RunMusicService runMusicService;
    private Logger logger = LoggerFactory.getLogger(MusicTypeAdminController.class);

    @RequestMapping(value = "/editMusicType", method = RequestMethod.POST)
    public APIResponse<?> editMusicType(@RequestBody @Validated(Insert.class) MusicTypeVo musicTypeReq) {
        APIResponse<?> result = runMusicService.editMusicType(musicTypeReq);
        return result;
    }

    @RequestMapping(value = "/deleteMusicType", method = RequestMethod.POST)
    public APIResponse<?> deleteMusicType(@RequestBody Map<String, Object> paramMap) {
        Byte musicType = MapUtils.getByte(paramMap, "musicType");
        APIResponse<?> result = runMusicService.deleteMusicType(musicType);
        return result;
    }

    @RequestMapping(value = "/musicTypeList", method = RequestMethod.POST)
    public APIResponse<PageObj<List<MusicTypeVo>>> musicTypeList(@RequestBody Map<String, Object> paramMap) {
        Integer pageNum = MapUtils.getInteger(paramMap, "pageNum");
        Integer pageSize = MapUtils.getInteger(paramMap, "pageSize");
        Byte type = MapUtils.getByte(paramMap, "type");
        String name = MapUtils.getString(paramMap, "name");
        Double pace = MapUtils.getDouble(paramMap, "pace");
        Integer cadence = MapUtils.getInteger(paramMap, "cadence");
        PageObj<List<MusicTypeVo>> result = runMusicService.musicTypeList(type, name, pace, cadence, pageNum, pageSize);
        return APIResponse.returnSuccess(result);
    }

    @RequestMapping(value = "/getMusicTypeListAdmin", method = RequestMethod.POST)
    public APIResponse<List<MusicTypeVo>> getMusicTypeList() {
        APIResponse<List<MusicTypeVo>> result = runMusicService.getMusicTypeListAdmin();
        return result;
    }


}

